﻿using System;
using NUnit.Framework;
using SvnFlow;

namespace SvnFlowTests
{
    [TestFixture]
    public class HistoryItemTest
    {
        [Test]
        public void DateParseTest()
        {
            var item = new HistoryItem();

            item.Time = "2010-11-11";
            Assert.AreEqual(new DateTime(2010, 11, 11, 0, 0, 0), item.ParsedTime);

            item.Time = "2010-11-11T12:13";
            Assert.AreEqual(new DateTime(2010, 11, 11, 12, 13, 0), item.ParsedTime);

            item.Time = "2010-11-11 12:13";
            Assert.AreEqual(new DateTime(2010, 11, 11, 12, 13, 0), item.ParsedTime);

            item.Time = "2010-11-11T12:13:30";
            Assert.AreEqual(new DateTime(2010, 11, 11, 12, 13, 30), item.ParsedTime);

            item.Time = "2010-11-11 12:13:30";
            Assert.AreEqual(new DateTime(2010, 11, 11, 12, 13, 30), item.ParsedTime);

            item.Time = "2010-11-11T19:27:05.9078010";
            Assert.IsTrue(
                new DateTime(2010, 11, 11, 19, 27, 5, 907) < item.ParsedTime
                && item.ParsedTime < new DateTime(2010, 11, 11, 19, 27, 5, 908));

            item.Time = "2010-11-11 19:27:05.907";
            Assert.AreEqual(new DateTime(2010, 11, 11, 19, 27, 5, 907), item.ParsedTime);

            Assert.Throws<FormatException>(() => item.Time = "2010-11-1119:27:05.9078010");

            item.Time = "2010.11.11";
            Assert.AreEqual(new DateTime(2010, 11, 11, 0, 0, 0), item.ParsedTime);
        }
    }
}
